package net.monare.mifss.admin.ui.comp;

import net.monare.mifss.evn.RemovePropertyListener;

import com.vaadin.server.ThemeResource;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.themes.BaseTheme;

public class PropertyFieldUi extends VerticalLayout {

	private static final long serialVersionUID = 6368289867030882788L;

	private TextField key;
	private TextField value;

	private RemovePropertyListener removeListener;

	public PropertyFieldUi(String keyWidth, String valueWidth) {

		key = new TextField();
		key.setWidth(keyWidth);

		value = new TextField();
		value.setWidth(valueWidth);

		removeListener = new RemovePropertyListener(this);

		Label spacer = new Label(" ");
		spacer.setWidth("4px");
		Button pictureButton = new Button();

		pictureButton.setStyleName(BaseTheme.BUTTON_LINK);
		pictureButton.setIcon(new ThemeResource("img/remove.png"));
		pictureButton.addClickListener(removeListener);

		HorizontalLayout fields = new HorizontalLayout();

		fields.addComponent(key);
		fields.setComponentAlignment(key, Alignment.MIDDLE_LEFT);
		fields.addComponent(value);
		fields.setComponentAlignment(value, Alignment.MIDDLE_LEFT);
		fields.addComponent(spacer);
		fields.addComponent(pictureButton);
		fields.setComponentAlignment(pictureButton, Alignment.MIDDLE_LEFT);

		addComponent(fields);

	}
	
	public void setPropertyKey(String keyValue){
		key.setValue(keyValue);
	}
	
	public void setPropertyValue(String valueValue){
		value.setValue(valueValue);
	}
	
	public String getKey(){
		return key.getValue();
	}

	public String getValue(){
		return value.getValue();
	}

}
